package com.csu.geo.service;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Query;

import org.hibernate.sql.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.csu.geo.entity.NgccNewPolygon;
import com.csu.geo.repository.NgccNewPolygonDao;

@Component
@Transactional
public class NgccNewPolygonService {

	@Autowired
	private NgccNewPolygonDao ngccNewPolygonDao;
	@Autowired
	private EntityManagerFactory entityManagerFactory;

	private int updatePolygon(NgccNewPolygon newPolygon) {
		String hql = "update Ngccnewpolygon as np set np.fName=:fname, np.fType=:ftype,np.version=:version,np.geom=:geom" + "where np.id=:id";
		EntityManager entityManager = entityManagerFactory.createEntityManager();
		Query query = entityManager.createNativeQuery(hql);
		query.setParameter("fname", newPolygon.getfName());
		query.setParameter("ftype", newPolygon.getfType());
		query.setParameter("version", newPolygon.getVersion());
		query.setParameter("geom", newPolygon.getGeom());
		query.setParameter("id", newPolygon.getId());
		int flag = query.executeUpdate();
		entityManager.getTransaction().commit();
		entityManager.close();
		return flag;
	}
	private String savenewPolygon(NgccNewPolygon newPolygon){
		if(ngccNewPolygonDao.save(newPolygon)!=null){
			return "0000";
		}
		else
		{
			return "0001";
		}
	}
	
}
